<!--
   xx项目-流程设计
-->
<template>
  <div>
    <el-dialog :title="projectName+'---问题设计'" size="large" v-model="dialogVisible" :before-close="closeDialog"
               v-on:open="onSubmit" :close-on-click-modal="false">
      <el-button type="primary" @click="addLinkDialog()" style="margin-bottom: 10px">
        <i class="el-icon-plus"></i>新增问题
      </el-button>
      <template>
                    <el-table
                      :data="historyGroup"
                      border
                      height="300"
                      style="width: 100%">
                      <el-table-column
                        type="index"
                        label="序号"
                        width="90">
                      </el-table-column>
                      <el-table-column
                        prop="question"
                        label="问题"
                        width="800">
                      </el-table-column>
                      <el-table-column
                        label="入选答案"
                        width="120">
                        <template  slot-scope="scope">
                         {{answerBox[scope.row.answer]}}
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="入排分类"
                        width="120">
                        <template  slot-scope="scope">
                         {{typeBox[scope.row.type]}}
                        </template>
                      </el-table-column>
                      <el-table-column
                        fixed="right"
                        label="操作"
                         >
                        <template  slot-scope="scope">
           
                            <el-button type="text" @click.native="opensf(scope.row.id)">删除</el-button>
                      </template>
                      </el-table-column>
                    </el-table>
                  </template>
      <div style="padding-bottom:20px;">
        
       
      </div>
        <el-button @click="closeDialog" style="float: right;">关闭</el-button>
        
    </el-dialog>
    <el-dialog
        width="50%"
        title="添加问题"
        :visible.sync="linkDialog.show"
        append-to-body>
            <div class="Signs">
              <div class="demo-input-suffix">
                <template>
                请输入问题：
                  <el-input
                    type="textarea"
                    :rows="2"
                    placeholder="请输入问题"
                    v-model="problem" style="margin-top:10px;">
                  </el-input>
                </template>
              </div>
              <div class="demo-input-suffix">
                <template>
                  入选答案：
                    <el-radio-group v-model='Answer'>
                      <el-radio :label="1">是</el-radio>
                      <el-radio :label="2">否</el-radio>
                    </el-radio-group>
                  </template>
              </div>
                  <div class="demo-input-suffix">
                     <template>
                     入排分类：
                        <el-radio-group v-model='category'>
                          <el-radio :label="1">纳入标准</el-radio>
                          <el-radio :label="2">排除标准</el-radio>
                          <!-- <el-radio :label="3">其他</el-radio> -->
                        </el-radio-group>
                      </template>
                  </div>
                 
                  
                 
                 
            
          
                <el-button type="primary" class="addBing addBingRight" @click='addVital()'>添加问题</el-button>
          </div>
      </el-dialog>
  </div>
</template>
<script>
  import http from '../../../api/http'

  export default {
    data() {
      return {
        answerBox:{
          1:"是",
          2:"否"
        },
        typeBox:{
          1:"纳入标准",
          2:"排除标准",
          3:"其他"
        },
        problem:'',
        Answer:'',
        category:'',
        historyGroup: [],
        linkDialog: {show: false},
        flowList: [],
        processId: null,
        cyclesList:[],
        activeCycles:'1',
        visible2:false,
      }
    },
    props: {
      addProcessVisible: {
        type: Boolean,
        default: false
      },
      projectId: {
        type: String
      }, projectName: {
        type: String
      }
    },
    computed: {
      dialogVisible: {
        get: function () {
          return this.addProcessVisible
        },
        set: function () {
        }
      }
    },
    methods: {
      
      deleteProcess(row) {
        var vm = this;
        
        http.postData(vm, "/pt/process/del/" + row.id, {}, function (resp) {
          var ret = resp.body;
          if (ret.code === '111') {

            vm.$notify({title: '删除提示', message: ret.msg, type: 'success'});
            vm.onSubmit();
          } else {
            vm.$message({type: 'error', message: ret.msg});
          }
        });
      },
      //
      opensf(id){
          var vm = this;
        
        http.postData(vm, "/pt/screening/quesDelete", {id:id,proid:vm.projectId}, function (resp) {
          var ret = resp.body;
          // console.log(resp)
          if (ret.code === '111') {

            vm.$notify({title: '删除提示', message: ret.msg, type: 'success'});
            vm.onSubmit();
          } else {
            vm.$message({type: 'error', message: ret.msg});
          }
        });
      },
      // 添加问题
      addVital(){
          var vm = this;
              http.postData(vm, "/pt/screening/questions", {question:vm.problem,answer:vm.Answer,type:vm.category,proid:vm.projectId}, function (resp) {
                var ret = resp.body;
                vm.$notify({
                    title: '成功',
                    message: ret.msg,
                    type: 'success'
                  });
                // console.log(resp);
                if (ret.code === '111') {
                    vm.linkDialog.show=false;
                    vm.problem='';
                    vm.Answer='';
                    vm.category='';
                    vm.onSubmit();
                } else {
                  
                }
              });
      },
      top(sortNo, id) {
        var vm = this;
        http.postData(vm, "/pt/process/top/" + sortNo + "-" + id + "-" + vm.projectId, {}, function (resp) {
          var ret = resp.body;
          if (ret.code === '111') {
            vm.$message({title: '操作提示', message: ret.msg, type: 'success'});
            vm.onSubmit();
          } else {
            vm.$message({type: 'error', message: ret.msg});
          }
        })
      },
      bottom(sortNo, id) {
        var vm = this;
        http.postData(vm, "/pt/process/bottom/" + sortNo + "-" + id + "-" + vm.projectId, {}, function (resp) {
          var ret = resp.body;
          if (ret.code === '111') {
            vm.$message({title: '操作提示', message: ret.msg, type: 'success'});
            vm.onSubmit();
          } else {
            vm.$message({type: 'error', message: ret.msg});
          }
        })
      },
      up(sortNo, id) {
        var vm = this;
        http.postData(vm, "/pt/process/up/" + sortNo + "-" + id + "-" + vm.projectId, {}, function (resp) {
          var ret = resp.body;
          if (ret.code === '111') {
            vm.$message({title: '操作提示', message: ret.msg, type: 'success'});
            vm.onSubmit();
          } else {
            vm.$message({type: 'error', message: ret.msg});
          }
        })
      },
      down(sortNo, id) {
        var vm = this;
        http.postData(vm, "/pt/process/down/" + sortNo + "-" + id + "-" + vm.projectId, {}, function (resp) {
          var ret = resp.body;
          if (ret.code === '111') {
            vm.$message({title: '操作提示', message: ret.msg, type: 'success'});
            vm.onSubmit();
          } else {
            vm.$message({type: 'error', message: ret.msg});
          }
        })
      }, addLinkDialog(id_) {
        this.processId = id_;
        this.linkDialog.show = true;
          this.problem=''; 
            this.Answer='';  
            this.category='';
      }, closeLinkDialog() {
        this.linkDialog.show = false;
      },
      loadCyclesList(){
        var vm = this;
        http.postData(vm, "/pt/process/cyclesList/" + vm.projectId,{}, function (resp) {
          var ret = resp.body;
          if (ret.code == '111') {
            vm.cyclesList = ret.value;
          }
        });
      },
      onSubmit() {
        var vm = this;
        /**
         * 加载流程设计信息
         */
        http.postData(vm, "/pt/screening/questionList" , {proid:vm.projectId}, function (resp) {
          var ret = resp.body;
           // console.log(resp)
          if (ret.code == '111') {
            // vm.flowList = ret.value;
            vm.historyGroup=ret.value;
            // vm.loadCyclesList();
          }
        });
      },
      updateCyclesEmptyStomach(data){
        var vm = this;
        this.$confirm('将按周期的空腹状态设置为'+(data.emptyStomach==0?'非空腹':'空腹')+', 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          http.postData(vm, "/pt/process/updateCyclesEmptyStomach/" + vm.projectId + '-' + data.cycles + '-' + data.emptyStomach, {}, function (resp) {
            var ret = resp.body;
//            if (ret.code == '111') {
              vm.loadCyclesList();
//            }else{
//              data.emptyStomach=data.emptyStomach==0?1:0;
//            }
          },function(err){data.emptyStomach=data.emptyStomach==0?1:0;});
        },()=>{
//          data.emptyStomach=data.emptyStomach==0?1:0;
          vm.loadCyclesList();
        });
      },
      closeDialog() {
        
        this.$parent.closeProblemDialog();
      },
   
      removeCycles(targetName){
        var vm=this;
        if(targetName=='1'){
          vm.$message({type: 'error', message:"周期1不能删除"});
          return;
        }
        this.$confirm('此操作将永久删除该周期节点, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          /**
           * 加载流程设计信息
           */
          http.postData(vm, "/pt/process/removeCycles/" + vm.projectId+'-'+vm.activeCycles, {}, function (resp) {
            var ret = resp.body;
            if (ret.code == '111') {
              vm.activeCycles='1';
              vm.onSubmit();
              vm.$message({type: 'success', message: ret.msg});
            }else {
              vm.$message({type: 'error', message: ret.msg});
            }
          });
        }).catch(() => {

        });
      },
      handleSizeChange(){
        this.form.pageNo = 1
        this.onSubmit()
      },
      handleCurrentChange(val) {
        this.form.pageNo = val
        this.onSubmit()
      }
    },
    components: {
    },
    created() {
      var vm = this;
//      vm.onSubmit();
//      vm.loadCyclesList();
      vm.$watch('activeCycles',function(newVal,oldVal){
        vm.onSubmit();
      })
    }
  }
</script>
